package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageDTO;
import com.itheima.entity.PageResult;
import com.itheima.mapper.BrandMapper;
import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wa1nut
 */
@Service
@Slf4j
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;
    @Override
    public PageResult<Brand> page(PageDTO pageDTO,Brand brand) {
        log.info("{}",pageDTO);
        PageHelper.startPage(pageDTO.getPage(),pageDTO.getSize());
        List<Brand> pages = brandMapper.selectByCondition(brand);
        Page<Brand> page = (Page<Brand>) pages;
        log.info("{}",page);
        return new PageResult<>(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Brand brand) {
        brandMapper.insert(brand);
    }

    @Override
    public void delete(Integer id) {
        brandMapper.delete(id);
    }

    @Override
    public Brand findById(Integer id) {
        return brandMapper.findById(id);
    }

    @Override
    public void update(Brand brand) {
        brandMapper.update(brand);
    }
}
